// 谁先成功  就成功,  谁先失败就失败
;(function(){
    //return
    let one = new Promise((resolve) => {
      resolve(1)
  })
  let one2 = new Promise((resolve) => {
      resolve(2)
  })
  let one3 = new Promise((resolve) => {
      resolve(3)
  })
  let a = Promise.race([one, one2, one3]).then(res => {
      console.log(res, "<==res")
  })
  console.log('看谁跑的快',a);
  })();


// 全部已决则为成功
;(function(){
//   return
  let one = new Promise((resolve) => {
    resolve(1)
})
let one2 = new Promise((resolve) => {
    resolve(2)
})
let one3 = new Promise((resolve) => {
    resolve(3)
})
let a = Promise.allSettled([one, one2, one3]).then(res => {
    console.log(res, "<==res")
})
console.log('全部已决了',a);
})();

// 全部任务成功才是成功
; (function () {
    return
    let one = new Promise((resolve) => {
        resolve(1)
    })
    let one2 = new Promise((resolve) => {
        resolve(2)
    })
    let one3 = new Promise((resolve) => {
        resolve(3)
    })
    let a = Promise.all([one, one2, one3]).then(res => {
        console.log(res, "<==res")
    })
    console.log(a);

})();

// 全部任务失败才是失败
; (function () {
    return
    let one = Promise.reject(1)
    let one2 = Promise.reject(2)
    let one3 = Promise.reject(3)
    let one4 = Promise.reject(4)
    Promise.any([one, one2, one3,one4]).then((res) => {
        console.log(res)
     }, (err) => {
        console.log('===>',err.errors);
    })
})();

; (function () {
    return

    new Promise((res, rej) => {
        console.log(11)
        res()
        new Promise((res, rej) => {
            console.log(22)
            res()
        }).then(res => {

            console.log(44)
        })
    }).then(res => {
        console.log(55)
    })
    console.log(33);

    // 顺序是11 22 33 44 55
})();



// 直接返回一个完成状态的promise
; (function () {
    return
    let a = Promise.resolve(11)
    //   相当于
    let b = new Promise((resolve) => {
        resolve(11)
    })
    console.log(a);
    console.log(b);
})();